/**
 * @author ZhiWen Ren
 * @version 1.0
 * @description: LeetCode-198-打家劫舍
 * @date 2025/7/26 14:43
 */
public class Solution198 {
    public int rob(int[] nums) {
        int[] money = new int[nums.length];
        int max = nums[0];
        int ans = max;

        for (int i = 0; i < nums.length; i++) {
            if (i < 2) {
                money[i] = nums[i];
            } else {
                max = Math.max(max, money[i - 2]);
                money[i] = max + nums[i];
            }
            ans = Math.max(ans, money[i]);
        }
        return ans;
    }
}
